
# dump by gdb's info proc map
map = """
          Start Addr           End Addr       Size     Offset objfile
            0x400000           0x401000     0x1000        0x0 /mnt/hgfs/share/coding/demo
            0x600000           0x601000     0x1000        0x0 /mnt/hgfs/share/coding/demo
            0x601000           0x602000     0x1000     0x1000 /mnt/hgfs/share/coding/demo
      0x7ffff7a0d000     0x7ffff7bcd000   0x1c0000        0x0 /lib/x86_64-linux-gnu/libc-2.23.so
      0x7ffff7bcd000     0x7ffff7dcd000   0x200000   0x1c0000 /lib/x86_64-linux-gnu/libc-2.23.so
      0x7ffff7dcd000     0x7ffff7dd1000     0x4000   0x1c0000 /lib/x86_64-linux-gnu/libc-2.23.so
      0x7ffff7dd1000     0x7ffff7dd3000     0x2000   0x1c4000 /lib/x86_64-linux-gnu/libc-2.23.so
      0x7ffff7dd3000     0x7ffff7dd7000     0x4000        0x0
      0x7ffff7dd7000     0x7ffff7dfd000    0x26000        0x0 /lib/x86_64-linux-gnu/ld-2.23.so
      0x7ffff7fda000     0x7ffff7fdd000     0x3000        0x0
      0x7ffff7ff8000     0x7ffff7ffa000     0x2000        0x0 [vvar]
      0x7ffff7ffa000     0x7ffff7ffc000     0x2000        0x0 [vdso]
      0x7ffff7ffc000     0x7ffff7ffd000     0x1000    0x25000 /lib/x86_64-linux-gnu/ld-2.23.so
      0x7ffff7ffd000     0x7ffff7ffe000     0x1000    0x26000 /lib/x86_64-linux-gnu/ld-2.23.so
      0x7ffff7ffe000     0x7ffff7fff000     0x1000        0x0
      0x7ffffffde000     0x7ffffffff000    0x21000        0x0 [stack]
  0xffffffffff600000 0xffffffffff601000     0x1000        0x0 [vsyscall]
"""
import re
import os


def get_module_info(map):
    lines = map.split("\n")
    stage = 0
    mod = {}
    for l in lines:
        m = re.split("\s+", l.strip())
        if "Start" in l:
            stage = 1
            continue
        if stage == 0:
            continue
        if len(m) > 1 and m[-1] not in mod:
            base = os.path.basename(m[-1])
            mod[base] = int(m[0], 16)
    return mod

print(get_module_info(map))